import { beforeUploadingApi } from '../api/index.js'
export const getQiniuData = async () => {
	try{
		const res = await beforeUploadingApi()
		return res
	} catch(e) {
		return Promise.reject(e)
	}
}

export const uploadQiniu = function (item, img) {
	return new Promise((resolve, reject) => {
		console.log(img)
		uni.uploadFile({
			url: item.upload_url,
			filePath: img.path,
			name: 'file',
			formData: {
				'token': item.upload_token,
				'key': (new Date().getTime()).toString() + parseInt(Math.random() * (999999 - 100000 + 1) + 100000, 10)
			},
			success: (res) => {
				console.log(123, res)
				if (res.statusCode < 200 || res.statusCode > 300) {
					reject('statusCode is not 200 series')
				} else {
					resolve(JSON.parse(res.data))
					console.log(res, '上传成功回调')
				}
			},
			fail: (err) => {
				console.log(err)
				reject(err)
			}
		})
	})
}